package com.primb.bench.project.init.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.primb.baselibs.util.PreferencesUtils;
import com.primb.baselibs.view.AutoToolbar;
import com.primb.bench.R;
import com.primb.bench.base.SwipeBaseActivity;
import com.primb.bench.common.module.http.service.ApiClient;
import com.primb.netlibs.config.ApiConstants;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Chen on 2017/7/14.
 * 功能描述：
 */

public class SettingActivity extends SwipeBaseActivity {
    @BindView(R.id.title_bar)
    TextView titleBar;
    @BindView(R.id.tv_top)
    TextView tvTop;
    @BindView(R.id.tool_bar)
    AutoToolbar toolBar;
    @BindView(R.id.et_setting_ip)
    EditText etSettingIp;

    @Override
    protected int onBaseLayoutId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_setting;
    }

    @Override
    protected void onBaseBindView() {
        tvTop.setVisibility(View.VISIBLE);
        tvTop.setText("保存");
        titleBar.setText("服务器IP地址设置");
        toolBar.setNavigationOnClickListener(v -> SettingActivity.this.finish());
        etSettingIp.setText(ApiConstants.BASE_URL);
    }

    @Override
    protected void onLoadData() {

    }

    @OnClick(R.id.tv_top)
    public void onViewClicked() {
        String ip = etSettingIp.getText().toString();
        if (ip != null && !ip.equals("")) {
            ApiConstants.BASE_URL = ip;
            ApiClient.retrofit = null;
            if (PreferencesUtils.putString(this, "ip", ip)) {
                showToast("保存成功");
                this.finish();
            }
        }
    }
}
